個人的 Finch CLI チートシート を作ってみた
こんにちは!AWS事業本部コンサルティング部のたかくに(@takakuni_)です。
皆さん Finch 触っていますか?
昨年、 コンテナ開発用のオープンソースクライアントとして、AWS から Finch が発表されました。
今回は Finch を触る機会があったため、個人的に今後使いそうなコマンドをまとめてみようと思います。
インストール
執筆時点(2023年3月8日)では、 macOS クライアントのみ提供されています。
詳しい前提条件は、Installing Finch - GitHubをご覧ください。
Homebrew を利用したインストール
Finch は HomeBrew Cask より提供されています。
brew install --cask finch
Finch VM の初期化
Finch の初回インストール後は、以下のコマンドで Finch VM (実行環境)の初期化(セットアップ)が必要です。
finch vm init
コマンド実行例
$ finch vm init
INFO[0000] Initializing and starting Finch virtual machine...
INFO[0063] Finch virtual machine started successfully
仮想マシン
Finch VM の起動
ローカルマシンが停止すると、 Finch VM も停止状態になります。
以下のコマンドで Finch VM を開始できます。
finch vm start
コマンド実行例
# 停止中の VM に対しての実行結果
$ finch vm start
INFO[0000] Starting existing Finch virtual machine...
INFO[0022] Finch virtual machine started successfully
# 起動中の VM に対しての実行結果
$ finch vm start
FATA[0000] the instance "finch" is already running
Finch VM の停止
同様に Finch を停止したい場合は、以下のコマンドで Finch VM を停止できます。
finch vm stop
コマンド実行例
# 起動中の VM に対しての実行結果
$ finch vm stop
INFO[0000] Stopping existing Finch virtual machine...
INFO[0002] Finch virtual machine stopped successfully
# 停止中の VM に対しての実行結果
$ finch vm stop
FATA[0000] the instance "finch" is already stopped
Finch VM のステータス確認
finch vm status
コマンド実行例
# 起動中の VM に対しての実行結果
$ finch vm status
Running
# 停止中の VM に対しての実行結果
$ finch vm status
Stopped
Finch VM の設定
デフォルトでは${HOME}/.finch/finch.yaml
に、仮想マシンの設定が記載されています。
執筆時点では、 仮想マシンのリソース制限のオプションと、外部ストレージをマウントするために利用するディレクトリ設定のみサポートです。
# CPUs: the amount of vCPU to dedicate to the virtual machine. (required)
cpus: 4
# Memory: the amount of memory to dedicate to the virtual machine. (required)
memory: 4GiB
# AdditionalDirectories: the work directories that are not supported by default. In macOS, only home directory is supported by default.
# For example, if you want to mount a directory into a container, and that directory is not under your home directory,
# then you'll need to specify this field to add that directory or any ascendant of it as a work directory. (optional)
additional_directories:
# the path of each additional directory.
- path: /Volumes
基本
バージョン確認
finch -v
実行例
$ finch -v
finch version v0.4.1
ヘルプの表示
finch --help
コマンド実行例
$ finch --help
Finch: open-source container development tool
Usage:
finch [command]
Available Commands:
build Build an image from Dockerfile
builder Manage builds
commit Create a new image from a container's changes
completion Generate the autocompletion script for the specified shell
compose Compose
container Manage containers
cp Copy files/folders between a running container and the local filesystem
create Create a new container
events Get real time events from the server
exec Run a command in a running container
help Help about any command
history Show the history of an image
image Manage images
images List images
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a container registry
logout Log out from a container registry
logs Fetch the logs of a container
network Manage networks
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image from a registry
push Push an image or a repository to a registry
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
system Manage containerd
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Shows Finch version information
vm Manage the virtual machine lifecycle
volume Manage volumes
wait Block until one or more containers stop, then print their exit codes
Flags:
--debug running under debug mode
-h, --help help for finch
-v, --version version for finch
Use "finch [command] --help" for more information about a command.
プラットフォームの指定
--platform
フラグを付与することで、アーキテクチャをまたいだコンテナの構築と実行が可能です。
※ DOCKER_DEFAULT_PLATFORM
のような環境変数は未サポートでした。
finch run --rm --platform=amd64 <image_name> SHELL
実行例
uname -ms
Darwin arm64
finch run --rm --platform=amd64 public.ecr.aws/amazonlinux/amazonlinux uname -ms
Linux x86_64
ECR へのログイン
finch login
の部分が注意です。
aws ecr get-login-password --region <REGION> | finch login --username AWS --password-stdin 123456789012.dkr.ecr.<REGION>.amazonaws.com
コマンド実行例
aws ecr get-login-password --region ap-northeast-1 | finch login --username AWS --password-stdin 123456789012.dkr.ecr.ap-northeast-1.amazonaws.com
WARNING: Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
イメージ
基本的にはdocker
の部分がfinch
に置き換わったと思っていただいて良いかと思います。
※ 新形式(finch image build
)のコマンドのみ記載していますが、旧形式(finch build
)のコマンドでも動きました。
イメージの作成
finch image build -t <image_name>:<tag_name> <path_Dockerfile>
コマンド実行例
$ finch image build -t hello-finch:latest .
[+] Building 1.9s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 270B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for public.ecr.aws/docker/library/golang:1.19 1.7s
=> [builder 1/4] FROM public.ecr.aws/docker/library/golang:1.19@sha256:5ba5ed13de753eb50daef1a750f78a1ec6ebd9fbb58b5a7a608efd5df7429c57 0.0s
=> => resolve public.ecr.aws/docker/library/golang:1.19@sha256:5ba5ed13de753eb50daef1a750f78a1ec6ebd9fbb58b5a7a608efd5df7429c57 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 112B 0.0s
=> CACHED [builder 2/4] WORKDIR /build 0.0s
=> CACHED [builder 3/4] COPY . . 0.0s
=> CACHED [builder 4/4] RUN CGO_ENABLED=0 go build -a -o hello-finch . 0.0s
=> CACHED [stage-1 1/2] COPY --from=builder /build/hello-finch /app/ 0.0s
=> CACHED [stage-1 2/2] WORKDIR /app 0.0s
=> exporting to oci image format 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:b981519df047cc6cba647956cca4fb681a5dcc2a54a0e9626270dcb285e877f3 0.0s
=> => exporting config sha256:583f4e37811486de58e7b800363a3fd6eb1ddb623a7865e1b939a803434178a5 0.0s
=> => sending tarball 0.0s
unpacking docker.io/library/hello-finch:latest (sha256:b981519df047cc6cba647956cca4fb681a5dcc2a54a0e9626270dcb285e877f3)...
Loaded image: docker.io/library/hello-finch:latest
キャッシュ無しのビルド
finch image build -t <image_name>:<tag_name> <path_Dockerfile> --no-cache
イメージの一覧表示
Docker CLI と違い、 -a, --all
フラグはデフォルトで有効化されていました。
finch image ls
コマンド実行例
$ finch image ls
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE
hello-finch latest fb5df55fa7ae 1 second ago linux/arm64 1.8 MiB 1008.5 KiB
イメージのプル
finch image pull <image_name>:<tag_name>
コマンド実行例
$ finch image pull public.ecr.aws/finch/hello-finch:latest
public.ecr.aws/finch/hello-finch:latest: resolved |++++++++++++++++++++++++++++++++++++++|
index-sha256:a71e474da9ffd6ec3f8236dbf4ef807dd54531d6f05047edaeefa758f1b1bb7e: done |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:705cac764e12bd6c5b0c35ee1c9208c6c5998b442587964b1e71c6f5ed3bbe46: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:6cc2bf972f32c6d16519d8916a3dbb3cdb6da97cc1b49565bbeeae9e2591cc60: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:ec080f7c92e9eb0227d60951f7c779648989116d97a5926f3e8684d4e46df196: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 4.3 s
イメージのタグ付け
finch image tag <source_image_name>:<tag_name> <target_image_name>:<tag_name>
コマンド実行例
$ finch image tag hello-finch:latest 123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/hello-finch
イメージのプッシュ
finch image push <image_name>:<tag_name>
コマンド実行例
# ECR にログインしてない時の挙動
finch image push 123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/hello-finch
INFO[0000] pushing as a reduced-platform image (application/vnd.docker.distribution.manifest.v2+json, sha256:fb5df55fa7aed8cc20a0eb4ea5dd4b46507a0e5cb596f9c15e6c853435b32f00)
manifest-sha256:fb5df55fa7aed8cc20a0eb4ea5dd4b46507a0e5cb596f9c15e6c853435b32f00: waiting |--------------------------------------|
config-sha256:20a59b4420ae9a8e23a8e5d55155edd9c8f937153110c1a7fee89bfcd5d92ae1: waiting |--------------------------------------|
elapsed: 0.1 s total: 0.0 B (0.0 B/s)
FATA[0000] unexpected status from HEAD request to https://123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/v2/hello-finch/blobs/sha256:644f27127721deb6315d1fa2836a800cac9838bc49b15c1d7d2551fc6a207fdb: 401 Unauthorized
FATA[0000] exit status 1
# ECR にログインした後の挙動
$ finch image push 123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/hello-finch
INFO[0000] pushing as a reduced-platform image (application/vnd.docker.distribution.manifest.v2+json, sha256:fb5df55fa7aed8cc20a0eb4ea5dd4b46507a0e5cb596f9c15e6c853435b32f00)
manifest-sha256:fb5df55fa7aed8cc20a0eb4ea5dd4b46507a0e5cb596f9c15e6c853435b32f00: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:20a59b4420ae9a8e23a8e5d55155edd9c8f937153110c1a7fee89bfcd5d92ae1: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 1.3 s total: 1.8 Ki (1.4 KiB/s)
イメージの削除
finch image rm <image_name>:<tag_name>
コマンド実行例
$ finch image rm hello-finch:latest
Untagged: docker.io/library/hello-finch:latest@sha256:fb5df55fa7aed8cc20a0eb4ea5dd4b46507a0e5cb596f9c15e6c853435b32f00
Deleted: sha256:e0fd40f03ea874b3e45446e023d4bddbf8bf821a9a29b32198c3ad109ebc2058
Deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
未使用イメージの削除
finch image prune --all
コマンド実行例
$ finch image prune --all
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
Untagged: 123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/hello-finch:latest
deleted: sha256:b9ef96f120076982ced57ccdacb4205e79790413717391cb37503af20fb2b060
deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
Untagged: docker.io/library/hello-finch:latest
deleted: sha256:b9ef96f120076982ced57ccdacb4205e79790413717391cb37503af20fb2b060
deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
Untagged: public.ecr.aws/finch/hello-finch:latest
deleted: sha256:7bab221560b6ff664327af5b53f4831b3d092116ed990cef3b6529e1e1b49cca
deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
イメージの変更履歴を確認
finch image history <image_name>:<tag_name>
コマンド実行例
$ finch image history hello-finch:latest
SNAPSHOT CREATED CREATED BY SIZE COMMENT
<missing> About an hour ago ENTRYPOINT ["./hello-finch"] 0.0 B buildkit.dockerfile.v0
sha256:71789d54b5e3e16eea9c8b7e2ba81b2072de2ec2cf9a4995a0fe41f1bd21fcb8 About an hour ago WORKDIR /app 4.0 KiB buildkit.dockerfile.v0
sha256:b9ef96f120076982ced57ccdacb4205e79790413717391cb37503af20fb2b060 About an hour ago COPY /build/hello-finch /app/ # buildkit 1.8 MiB buildkit.dockerfile.v0
イメージの詳細を確認
finch image inspect <image_name>:<tag_name>
コマンド実行例
$ finch image inspect public.ecr.aws/finch/hello-finch:latest
[
{
"Id": "sha256:583f4e37811486de58e7b800363a3fd6eb1ddb623a7865e1b939a803434178a5",
"RepoTags": [
"hello-finch:latest"
],
"RepoDigests": [
"hello-finch@sha256:b981519df047cc6cba647956cca4fb681a5dcc2a54a0e9626270dcb285e877f3"
],
"Comment": "buildkit.dockerfile.v0",
"Created": "2023-03-18T09:08:01.868230399Z",
"Author": "",
"Config": {
"AttachStdin": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"WorkingDir": "/app",
"Entrypoint": [
"./hello-finch"
]
},
"Architecture": "arm64",
"Os": "linux",
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:b9ef96f120076982ced57ccdacb4205e79790413717391cb37503af20fb2b060",
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
format フラグ
--format
フラグで出力結果を形式化することが可能。
finch image inspect <image_name>:<tag_name> --format "{{.Config.Env}}"
コマンド実行例
# Env のみ取得
$ finch image inspect public.ecr.aws/finch/hello-finch:latest --format "{{.Config.Env}}"
[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
コンテナ
カスタム名で実行
finch container run --name <container_name> <image_name>:<tag_name>
実行例
$ finch container run --name finch-container --rm public.ecr.aws/finch/hello-finch:latest
@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@ @@@@@@@@@@@
@@@@@@@ @@@@@@@
@@@@@@ @@@@@@
@@@@@@ @@@@@
@@@@@ @@@# @@@@@@@@@
@@@@@ @@ @@@ @@@@@@@@@@
@@@@% @ @@ @@@@@@@@@@@
@@@@ @@@@@@@@
@@@@ @@@@@@@@@@@&
@@@@@ &@@@@@@@@@@@
@@@@@ @@@@@@@@
@@@@@ @@@@@(
@@@@@@ @@@@@@
@@@@@@@ @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@
Hello from Finch!
Visit us @ github.com/runfinch
特定ポートを公開して実行
finch container run -p <host_port>:<container_port> <image_name>:<tag_name>
実行例
$ finch container run -p 80:80 --name nginx-container --rm public.ecr.aws/nginx/nginx:latest
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/03/18 13:33:19 [notice] 1#1: using the "epoll" event method
2023/03/18 13:33:19 [notice] 1#1: nginx/1.23.3
2023/03/18 13:33:19 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/03/18 13:33:19 [notice] 1#1: OS: Linux 6.1.14-200.fc37.aarch64
2023/03/18 13:33:19 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:1024
2023/03/18 13:33:19 [notice] 1#1: start worker processes
2023/03/18 13:33:19 [notice] 1#1: start worker process 29
2023/03/18 13:33:19 [notice] 1#1: start worker process 30
バックグラウンドで実行
finch container run -d <image_name>:<tag_name>
実行例
$ finch container run -p 80:80 --name nginx-container -d public.ecr.aws/nginx/nginx:latest
a94d3788495b36bf73339fbbc17b5b6cbfeebf22f6878f5bfc880eac07ddcd03
$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
[nginx.org](http://nginx.org/).<br/>
Commercial support is available at
[nginx.com](http://nginx.com/).</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
コンテナの起動 / 停止
finch container start|stop <container_name> (or <container-id>)
実行例
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e949519d791 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 3 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
# コンテナの停止
$ finch container stop nginx-container
nginx-container
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e949519d791 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 3 minutes ago Exited (0) 1 second ago 0.0.0.0:80->80/tcp nginx-container
# コンテナの起動
$ finch container start nginx-container
nginx-container
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e949519d791 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 3 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
コンテナの削除
finch container rm <container_name>
実行例
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e949519d791 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 5 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
# コンテナの停止
$ finch container stop nginx-container
nginx-container
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e949519d791 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 5 minutes ago Exited (0) 4 seconds ago 0.0.0.0:80->80/tcp nginx-container
# コンテナの削除
$ finch container rm nginx-container
nginx-container
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
コンテナの強制削除
finch container rm <container_name> --force
実行例
# コンテナの立ち上げ
$ finch container run -p 80:80 --name nginx-container -d public.ecr.aws/nginx/nginx:latest
069361ab0cda8a10982ddeae5364c216baa11dd542c95d7821000c7d788842f3
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
069361ab0cda public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 4 seconds ago Up 0.0.0.0:80->80/tcp nginx-container
# コンテナの削除(起動中のためエラーが出る)
$ finch container rm nginx-container
FATA[0000] you cannot remove a running container 069361ab0cda8a10982ddeae5364c216baa11dd542c95d7821000c7d788842f3. Stop the container before attempting removal or force remove
FATA[0000] exit status 1
# コンテナの強制削除
$ finch container rm nginx-container --force
nginx-container
# コンテナの一覧表示
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
実行中のコンテナに対してシェルを開く
finch container exec -it <container_name> sh
実行例
# コンテナの立ち上げ
$ finch container run -p 80:80 --name nginx-container -d public.ecr.aws/nginx/nginx:latest
f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88
# nginx コンテナのコンテンツ確認
$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
[nginx.org](http://nginx.org/).<br/>
Commercial support is available at
[nginx.com](http://nginx.com/).</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# nginx コンテナへのシェルの実行
$ finch container exec -it nginx-container sh
# echo finch-test > /usr/share/nginx/html/index.html
# exit 0
# nginx コンテナのコンテンツ確認
$ curl localhost
finch-test
コンテナの一覧表示
起動中のコンテナのみ表示する
finch container ls
実行例
$ finch container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5ef243abb63 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 10 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
すべてのコンテナを表示する
finch container ls -a
実行例
# 適当にコンテナを起動/停止
$ finch container run -p 80:80 --name nginx-stop-container -d public.ecr.aws/nginx/nginx:latest
f41c260dde48640c9c1cc7a4de5a055c7408ad4762e2c2c60e59805b4e3f9e0b
$ finch container stop nginx-stop-container
nginx-stop-container
# 起動中のコンテナのみ表示する
$ finch container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5ef243abb63 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 13 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
# すべてのコンテナを表示する
$ finch container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f41c260dde48 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 15 seconds ago Exited (0) 10 seconds ago 0.0.0.0:80->80/tcp nginx-stop-container
f5ef243abb63 public.ecr.aws/nginx/nginx:latest "/docker-entrypoint.…" 13 minutes ago Up 0.0.0.0:80->80/tcp nginx-container
コンテナのログ取得
finch container logs <container_name>
実行例
$ finch container logs nginx-container
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/03/18 14:17:05 [notice] 1#1: using the "epoll" event method
2023/03/18 14:17:05 [notice] 1#1: nginx/1.23.3
2023/03/18 14:17:05 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/03/18 14:17:05 [notice] 1#1: OS: Linux 6.1.14-200.fc37.aarch64
2023/03/18 14:17:05 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:1024
2023/03/18 14:17:05 [notice] 1#1: start worker processes
2023/03/18 14:17:05 [notice] 1#1: start worker process 29
2023/03/18 14:17:05 [notice] 1#1: start worker process 30
10.4.0.1 - - [18/Mar/2023:14:17:10 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.85.0" "-"
10.4.0.1 - - [18/Mar/2023:14:17:30 +0000] "GET / HTTP/1.1" 200 11 "-" "curl/7.85.0" "-"
コンテナの詳細確認
finch container inspect <container_name>
実行例
$ finch container inspect nginx-container
[
{
"Id": "f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88",
"Created": "2023-03-18T14:17:05.496329003Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"Pid": 14107,
"ExitCode": 0,
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "public.ecr.aws/nginx/nginx:latest",
"ResolvConfPath": "/var/lib/nerdctl/1935db59/containers/finch/f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88/resolv.conf",
"HostnamePath": "/var/lib/nerdctl/1935db59/containers/finch/f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88/hostname",
"LogPath": "/var/lib/nerdctl/1935db59/containers/finch/f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88/f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88-json.log",
"Name": "nginx-container",
"RestartCount": 0,
"Driver": "overlayfs",
"Platform": "linux",
"AppArmorProfile": "",
"Mounts": null,
"Config": {
"Hostname": "f5ef243abb63",
"AttachStdin": false,
"Labels": {
"io.containerd.image.config.stop-signal": "SIGQUIT",
"nerdctl/extraHosts": "null",
"nerdctl/hostname": "f5ef243abb63",
"nerdctl/log-uri": "binary:///usr/local/bin/nerdctl?_NERDCTL_INTERNAL_LOGGING=%2Fvar%2Flib%2Fnerdctl%2F1935db59",
"nerdctl/name": "nginx-container",
"nerdctl/namespace": "finch",
"nerdctl/networks": "[\"bridge\"]",
"nerdctl/platform": "linux/arm64/v8",
"nerdctl/ports": "[{\"HostPort\":80,\"ContainerPort\":80,\"Protocol\":\"tcp\",\"HostIP\":\"0.0.0.0\"}]",
"nerdctl/state-dir": "/var/lib/nerdctl/1935db59/containers/finch/f5ef243abb635b1f9e9c3bb98387e52920ce7abb1fd4019961fefb72f6684c88"
}
},
"NetworkSettings": {
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "10.4.0.29",
"IPPrefixLen": 24,
"MacAddress": "e6:70:8f:5e:30:8b",
"Networks": {
"unknown-eth0": {
"IPAddress": "10.4.0.29",
"IPPrefixLen": 24,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "e6:70:8f:5e:30:8b"
}
}
}
}
]
format フラグ
--format
フラグで出力結果を形式化することが可能。
finch container inspect <container_name> --format "{{.Image}}"
実行例
# Image のみ取得
$ finch container inspect nginx-container --format "{{.Image}}"
メトリクス取得
ライブストリーム形式でコンテナのメトリクスを表示する
finch stats
※ finch container stats
は存在しないため注意。
実行例
$ finch stats
# ライブストリーミング形式に切り替わる
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f5ef243abb63 nginx-contai 0.00% 2.641MiB / 16EiB 0.00% 38.2kB / 20.7kB 0B / 16.4kB 3
# CTRL + C
^CFATA[0003] exit status 255
非ストリーミング形式で出力
finch stats --no-stream
実行例
$ finch stats --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f5ef243abb63 nginx-contai 0.00% 2.641MiB / 16EiB 0.00% 38.2kB / 20.7kB 0B / 16.4kB 3
まとめ
以上、「個人的 Finch CLI チートシートを作ってみた」でした。
ほぼほぼ、動きが Docker CLI だったため、学習コストが少なめでよかったです。
Finch はまだまだ発展途中のため、徐々にチートシートも更新していこうと思います。
(反響よければ、docker compose 部分も追記できればと思います。)
このブログが誰かの参考になれば幸いです。AWS事業本部コンサルティング部のたかくに(@takakuni_)でした!